53
Access rights and inheritance
public
private
public
protected
private
protected
private
private
private
public
private
Type of inheritance
superclass
class
As a default, classes are privately derived from each other.
The type of inheritance influences the access rights to elements of the various superclasses.
Using public inheritance, everything which is declared private in a superclass remains private in the subclass. Similarly, everything which is public remains public.
The leftmost column lists possible access rights for elements of classes. It also includes a third type protected. This type is used for elements which should be
directly usable in subclasses but which should not be accessible from the outside. Thus, one could say elements of this type are between private and public
elements in that they can be used within the class hierarchy rooted by the corresponding class.
The second and third column show the resulting access right of the elements of a superclass when the subclass is privately and publically derived, respectively.